package com.geologyoa.persist;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.geologyoa.commons.JdbcUtil;
import com.geologyoa.domain.Function;


public class FunctionDaoImpl implements FunctionDao {
	Connection conn = null;
	PreparedStatement ps = null;
	ResultSet rs = null;
	public List<Function> SearchAllFunction() {
		Function function=null;
		List<Function> functionList=new ArrayList<Function>();
		   conn=JdbcUtil.getConnection();
		   String sql = "";
		   sql = "select * from function";
			try {
				ps = conn.prepareStatement(sql);
				rs=ps.executeQuery();
				while(rs.next())
				{
					function=new Function();
					function.setFunctionid(Integer.parseInt(rs.getString("functionid")));
					function.setFunctionname(rs.getString("functionname"));
				    functionList.add(function);
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return functionList;
	}

}
